from Bases import setID
from osc_base import OSCBaseObject

class Universe(OSCBaseObject):
    _saved_class_name = 'Universe'
    _saved_attributes = ['id', 'name']
    def __init__(self, **kwargs):
        self._name = None
        self.comm = kwargs.get('comm')
        super(Universe, self).__init__(**kwargs)
        if 'deserialize' not in kwargs:
            self.id = setID(kwargs.get('id'))
            self.name = kwargs.get('name', '')
        self.values = [0]*513
        self.register_attr_watch('name')
        dmx_io = kwargs.get('dmx_io', '')
        self.dmx_io = self.comm.dmx_io.get(dmx_io)
        
    def on_attribute_value_changed(self, **kwargs):
        attribute = kwargs.get('attribute')
        chan = attribute.chan
        value = kwargs.get('value')
        self.values[chan] = value
        if self.dmx_io is not None:
            self.dmx_io.sendDMXValue(chan, value)

    @property
    def name(self):
        return self._name
    @name.setter
    def name(self, value):
        self._name = value
        #self.osc_address = value
        #self.osc_node.setName(value)
